package com.situ.staffmgr.dao.impl;

import java.util.List;

import com.situ.staffmgr.dao.AdminDao;
import com.situ.staffmgr.entity.Admin;
import com.situ.staffmgr.util.BaseDaoT;

public class AdminDaoImpl implements AdminDao{
	private BaseDaoT dbUtil= new BaseDaoT();
	public int insert(Admin admin) {
		String sql= "insert into admin(username,password,salt,realname,phone,email)"+"value(?,?,?,?,?,?)";
		
		return dbUtil.update(sql, 
				admin.getUsername(),
				admin.getPassword(),
				admin.getSalt(),
				admin.getRealname(),
				admin.getPhone(),
				admin.getEmail());
	}


	public int update(Admin admin) {
		String sql  ="update admin set password=?,salt=?,realname=?,phone=?,email=?"+"where id=?";
	
		return dbUtil.update(sql, 
				admin.getPassword(),
				admin.getSalt(),
				admin.getRealname(),
				admin.getPhone(),
				admin.getEmail(),
				admin.getId());
	}

	public Admin selectBuUsername(String username) {
		String sql = "select * from admin where username=?";
		return dbUtil.selectOne(Admin.class, sql, username);
	}


	public Admin selectById(int id) {
		String sql = "select * from admin where id=?";
		return dbUtil.selectOne(Admin.class, sql, id);
	}

	public List<Admin> selectAll() {
		String sql = "select * from admin";
		return dbUtil.select(Admin.class, sql);
	}

}
